﻿using Microsoft.AspNetCore.Mvc;
using System;

namespace MVC_Demo.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            //数据的查询
            //把数据传递到视图上
            //返回显示的页面 规则
            return View();
        }
        public IActionResult ViewDataDemo()
        {
            //数据传出
            ViewData["数据的名字"] = "数据的值 可以支持多个数据类型";
            ViewData["name"] = "ken";
            ViewData["birthday"] = new DateTime(2000, 1, 1);
            ViewData["hobby"] = new string[] { "跑步", "阅读", "Coding" };

            //返回页面
            return View();
        }
        public IActionResult ViewBagDemo()
        {
            //传出
            ViewBag.数据的名字 = "数据的值 可以支持多个数据类型";
            ViewBag.Title = "ViewBag传值示例";
            ViewBag.Name = "ken";
            ViewBag.Birthday = new DateTime(2000, 1, 1);
            ViewBag.Hobby = new string[] { "跑步", "阅读", "Coding" };

            return View();
        }
        public IActionResult ViewModelDemo()
        {
            ViewBag.Title = "ViewModel传值示例";


            //人类对象的实例化 强类型
            var person = new Person
            {
                Name = "ken",
                Birthday = new DateTime(2000, 1, 1),
                Hobby = new string[] { "跑步", "阅读", "Coding" }
            };
            //等同于 return View("ViewModelDemo", person);
            //传出去
            return View(person);
        }
    }
}
